package org.openrbac.rbac.controller;


import org.openrbac.rbac.service.MailService;
import org.openrbac.rbac.ubean.QqUser;
import org.openrbac.rbac.utils.MailUtil;
import org.openrbac.rbac.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/public")
public class QqMailController {


    private MailUtil mailUtil = new MailUtil();

//    @PostMapping("/qqMails")
//    public R doMail(QqUser qqUser) {
//        System.out.println("数据: " + qqUser);
//        if (qqUser != null) {
//            MailBean mailBean = new MailBean();
//            mailBean.setReceiver(qqUser.getMailbox());//接收者
//            mailBean.setSubject("用户信息");//标题
//            //内容主体
//            mailBean.setContent("SpringBootMail发送一个简单格式的邮件，时间为：" + new Date());
//
//            mailUtil.sendSimpleMail(mailBean);
//            return R.ok("发送成功", qqUser);
//        }
//        return R.error("发送失败");
//    }


    @Autowired
    private MailService mailService;

    @PutMapping("/sendEmail")
    public boolean sendEmail(@RequestBody QqUser userVo){
        mailService.sendMimeMail(userVo.getEmail());
        return true;
    }

    @PostMapping("/register")
    public Object register(@RequestBody QqUser userVo){
        System.out.println(userVo.getEmail());
        if(mailService.registered(userVo)){
            return R.ok(true);
        }
        return R.error("注册失败");
    }
}
